package xps.and.uudaijia.userclient.util;

import android.animation.FloatEvaluator;
import android.animation.ObjectAnimator;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;

/**
 * Created by XPS on 2017/5/11.
 */
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public class AnimUtil {
    /**
     * 晃动动画
     *
     * @param counts 半秒钟晃动多少下
     * @return
     */
    public static Animation shakeAnimation(int counts) {
        Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
        translateAnimation.setInterpolator(new CycleInterpolator(counts));
        translateAnimation.setDuration(500);
        return translateAnimation;
    }

    public static ObjectAnimator getTransUpYAnim() {
        ObjectAnimator circleAnim = ObjectAnimator.ofFloat(null, "translationY", 0f, 40f);
        circleAnim.setDuration(500);
        return circleAnim;
    }

    public static ObjectAnimator getTranDownYAnim() {
        ObjectAnimator circleAnim = ObjectAnimator.ofFloat(null, "translationY", 40f, 0f);
        circleAnim.setDuration(500);
        return circleAnim;
    }

    public static void toalphaone(View view, int duration) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, "alpha", new FloatEvaluator(),0.0f,1.0f);
        objectAnimator.setDuration(duration);
        objectAnimator.start();
    }

    public static void scaleAnim(View view, int duration) {
        ObjectAnimator scaleXobjectAnimator = ObjectAnimator.ofObject(view, "scaleX", new FloatEvaluator(),1.0f,1.3f,1.0f);
        scaleXobjectAnimator.setDuration(duration);
        scaleXobjectAnimator.setInterpolator(new FastOutSlowInInterpolator());
        scaleXobjectAnimator.start();
        ObjectAnimator scaleYobjectAnimator = ObjectAnimator.ofObject(view, "scaleY", new FloatEvaluator(),1.0f,1.3f,1.0f);
        scaleYobjectAnimator.setDuration(duration);
        scaleYobjectAnimator.setInterpolator(new FastOutSlowInInterpolator());
        scaleYobjectAnimator.start();
    }

    public static void toalphazero(View view, int duration) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, "alpha", new FloatEvaluator(),0.0f,1.0f);
        objectAnimator.setDuration(duration);
        objectAnimator.start();
    }

}
